#include "ForwardRenderPiplinePlugin.h"
#include <SEForwardRenderPiplinePlugin/RenderTargetManager.h>
#include <SEForwardRenderPiplinePlugin/GBufferRenderPass.h>
#include <SEForwardRenderPiplinePlugin/ModelRenderPass.h>
#include <SEForwardRenderPiplinePlugin/PointLightShadowRenderPass.h>
#include <SEForwardRenderPiplinePlugin/SSRRenderPass.h>
#include <SERender/Resourses/Loader/TextureLoader.h>

namespace SEngine
{
    ForwardRenderPiplinePlugin::ForwardRenderPiplinePlugin(Renderer & renderer)
        : RenderPipline(renderer)
    {
    }

    void ForwardRenderPiplinePlugin::Init()
    {
        RenderTargetManager rtmanager;
        TextureLoader<Texture2D> texLoader;
        texLoader.SetInternalFormat(RGB32F);
        texLoader.SetFormat(RGB);
        texLoader.SetType(FLOAT);
        texLoader.SetParameter(TEXTURE_MAG_FILTER, LINEAR);
        texLoader.SetParameter(TEXTURE_MIN_FILTER, LINEAR);
        texLoader.SetParameter(TEXTURE_WRAP_S, CLAMP_TO_EDGE);
        texLoader.SetParameter(TEXTURE_WRAP_T, CLAMP_TO_EDGE);
        rtmanager.AddTarget("PositionRT", texLoader.CreateTexture());
        rtmanager.AddTarget("NormalRT", texLoader.CreateTexture());
        rtmanager.AddTarget("TangentRT", texLoader.CreateTexture());
        rtmanager.AddTarget("AlbedoRT", texLoader.CreateTexture());
        rtmanager.AddTarget("DepthRT", texLoader.CreateTexture());
        
        this->AddField<RenderTargetManager>(std::move(rtmanager));
        
        // this->NextPass<GBufferRenderPass>();
        // this->NextPass<TestRenderPass>();
        this->NextPass<ModelRenderPass>();
        // this->NextPass<ShadowRenderPass>();
        // this->NextPass<GizmoRenderPass>();
        
        // this->NextPass<PointLightShadowRenderPass>();
        // this->NextPass<BoundingShapeRenderPass>();
        // this->NextPass<SSAORenderPass>();
        // this->NextPass<SSRRenderPass>();
        // this->NextPass<DebugRenderPass>();
    }

    void ForwardRenderPiplinePlugin::Deinit()
    {
        this->Reset();
    }

    std::string ForwardRenderPiplinePlugin::Name()
    {
        return "ForwardRenderPiplinePlugin";
    }

    IPlugin *CreatePlugin(void* args)
    {
        return new ForwardRenderPiplinePlugin(*(Renderer*)args);
    }

    void DestroyPlugin(IPlugin *plugin)
    {
        delete plugin;
    }

} // namespace SEngine
